﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wintellect.PowerCollections;
using System.Text.RegularExpressions;

namespace Ex1.Students
{
    enum StudentGender
    {
        Male,
        Female
    }
    class Student
    {
        private static Set<long> uniqueSSN = new Set<long>();
        private string name;
        private int age;
        private int classNumber;
        private long sSN;
        private string dateOfBirth;
        private StudentGender gender;

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                if (value.Length < 10 || value.Length > 50)
                {
                    //throw new ArgumentException ("Name should be in interval (10;50)!");
                    throw new InvalidStudentException("Name should be in interval (10;50)!");
                }
                else
                {
                    this.name = value;
                }
            }
        }
        public int ClassNumber
        {
            get
            {
                return this.classNumber;
            }
            set
            {
                if (value < 1 || value > 11)
                {
                    //throw new ArgumentException("Class number should be in interval [1;11]!");
                    throw new InvalidStudentException("Class number should be in interval [1;11]!");
                }
                else
                {
                    this.classNumber = value;
                }
            }
        }
        public int Age
        {
            get
            {
                return this.age;
            }
            set
            {
                if (value < 1 || value > 101)
                {
                    //throw new ArgumentException("Entered age is not valid!");
                    throw new InvalidStudentException("Entered age is not valid!");
                }
                else
                {
                    this.age = value;
                }
            }
        }
        public string DateOfBirth
        {
            get
            {
                return this.dateOfBirth;
            }
            set
            {
                string expression = @"^([1-9]|[12][0-9]|3[01])[.]([1-9]|1[012])[.](19\d\d|200[0-9]|2010)$";
                if (Regex.IsMatch(value, expression))
                {
                    this.dateOfBirth = value;
                }
                else
                {
                    throw new ArgumentException("Date must be in 1.1.1900 – 1.1.2010 range and in [day].[month].[year] format!");
                }
            }
        }
        public long SSN
        {
            get
            {
                return this.sSN;
            }
            set
            {
                if (value > 999999999 || value < 99999999)
                {
                    throw new ArgumentException("SSN is not valid 9 digit number!");
                }
                else if (uniqueSSN.Contains(value))
                {
                    throw new ArgumentException("SSN is not unique in the system!");
                }
                else
                {
                    this.sSN = value;
                    uniqueSSN.Add(value);
                }
            }
        }
        public StudentGender Gender
        {
            get
            {
                return this.gender;
            }
            set
            {
                this.gender = value;
            }
        }

        public Student(string name, int age, int classNumber, StudentGender gender, long ssn,string dateOfBirth)
        {
            this.Name = name;
            this.Age = age;
            this.ClassNumber = classNumber;
            this.Gender = gender;
            this.SSN = ssn;
            this.DateOfBirth = dateOfBirth;
        }
    }

    class StudentsTest
    {
        static void Main(string[] args)
        {
            Student pesho = new Student("pesho123456", 21, 5, StudentGender.Male,123456789,"1.12.1900");

            //Student peshoSameSSN = new Student("pesho123456", 21, 5, StudentGender.Male,123456789, "1.12.1900");
        }
    }
}
